package com.mingmen.canting.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mingmen.canting.R;
import com.mingmen.canting.chushizhang.ChuShiRightAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yjwfn on 17-9-23.
 */

public class CaiGouRuKuAdapter extends RecyclerView.Adapter<CaiGouRuKuAdapter.PhotoViewHolder> {


    private int[] photos;

    Context context;
    List<String> myList;

    public CaiGouRuKuAdapter(Context context, List<String> myList) {
        this.context = context;
        this.myList = myList;
    }

    public void setDataList(List<String> myList) {
        this.myList = myList;
        notifyDataSetChanged();
    }


    @Override
    public PhotoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        return new PhotoViewHolder(inflater.inflate(R.layout.item_caigouruku, parent, false));
    }

    @Override
    public void onBindViewHolder(PhotoViewHolder holder, int position) {
//        holder.photoView.setImageResource(photos[position]);
        holder.text_name.setText(myList.get(position));
        List<String> second = new ArrayList<>();
        for (int i = 0; i < 15; i++) {
            second.add("Item_ITem" + i);
        }
        if (holder.chuShiRightAdapter == null) {
            holder.chuShiRightAdapter = new ChuShiRightAdapter(context, second, position);
            LinearLayoutManager layoutManage = new LinearLayoutManager(context);
            holder.rv_item.setLayoutManager(layoutManage);
//            holder.rvItemItem.addItemDecoration(new GridSpacingItemDecoration(2, 20, false));
            holder.rv_item.setAdapter(holder.chuShiRightAdapter);
        } else {
            holder.chuShiRightAdapter.setPosition(position);
            holder.chuShiRightAdapter.notifyDataSetChanged();
        }

    }

    @Override
    public int getItemCount() {
        return myList.size();
    }

    static final class PhotoViewHolder extends RecyclerView.ViewHolder {


        TextView text_name;
        RecyclerView rv_item;
        ChuShiRightAdapter chuShiRightAdapter;

        public PhotoViewHolder(View itemView) {
            super(itemView);

            text_name = itemView.findViewById(R.id.text_name);
            rv_item = itemView.findViewById(R.id.rv_item);
        }
    }
}
